//
// C++ Header: ProductDB
//
// Description: this class is a list containing Product objects parsed from files
//
//
// Author:  <>, (C) 2007
//
//
//

#ifndef PRODUCTDBH
#define PRODUCTDBH
#include <fstream>
#include <list>
#include "Product.h"
using namespace std;


//note : we did not code any implementation to reload/modify the database without:
//--either loading a file into the database again (which clears the list first and adds products again)
//--or browsing through the database and change the products's instances "by hand" in the file, or also using the interface of "list"
class ProductDB : public list<Product>
{
	public:
		//load DB object with contents from some file (or no file if fileName=="")
		ProductDB ( string fileName="" );
		
		//outputs info on the PROFIT GAINED IN DOLLAR
		//if stocks are sold out for :
		//- a single product, provided its exact name is found in database
		void showPredictedProfitOf (string&);
		//- all the products in total
		void showTotalPredictedProfit();
		
		//get the list of products with higher selling value than minValue
		ProductDB getProductsMoreExpensive(float minValue);
		
		//get the list of products with more units in stock than minValue
		ProductDB getMoreNumerousProducts(float minValue);

		//is the list empty of elements ? emptiness is also what results from
		//a failure in loading from a file
		operator bool();
		
		//OPERATORS >> AND <<
		
		//for: int nbEaten = (someFileStream >> dbInstance);
		friend int operator>> (istream& in, ProductDB& db);
		
		//for: int nb = ("someFileName" >> dbInstance);
		friend int operator>> (string& filename, ProductDB& db);
		friend int operator>> (const char* filename, ProductDB& db);
		
		//for: cout << dbInstance;
		//outputs all the products' details nicely
		friend ostream& operator<< ( ostream& out, ProductDB& db );
		
		
		// displays the names of the products
		void showNames();
		
		//write this database back into file name "where"
		//in the usual format (see AboutDataFilesFormatting.txt)
		bool writeTo_OtherFile(string& where);
	
	private:
		//called by constructor & operator >> functions
		int parseToDb(istream& in, ProductDB& tmpDb);
};
ostream& operator<< ( ostream& out, ProductDB& db );

int operator>> (istream& in, ProductDB& db) ;
int operator>> (string& filename, ProductDB& db) ;
int operator>> (const char* filename, ProductDB& db) ;
#endif
